package net.sunofbeaches.controller.admin;

import net.sunofbeaches.pojo.Looper;
import net.sunofbeaches.response.ResponseResult;
import net.sunofbeaches.services.ILoopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/loop")
public class LooperAdminApi {
    @Autowired
    private ILoopService iLoopService;

    @PreAuthorize("@permission.adminPermission()")
    @PostMapping
    public ResponseResult addLoop(@RequestBody Looper looper){
        return iLoopService.addLoop(looper);
    }

    @PreAuthorize("@permission.adminPermission()")
    @PutMapping("/{loopId}")
    public ResponseResult updateLoop(@PathVariable("loopId") String lookId,
                                     @RequestBody Looper looper){
        return iLoopService.updateLoop(lookId,looper);
    }

    @PreAuthorize("@permission.adminPermission()")
    @DeleteMapping("/{loopId}")
    public ResponseResult deleteLoop(@PathVariable("loopId")String loopId){
        return iLoopService.deleteLoop(loopId);
    }
    @PreAuthorize("@permission.adminPermission()")
    @GetMapping("/list")
    public ResponseResult listLoops(){
        return iLoopService.listLoops();
    }

    @PreAuthorize(("@permission.adminPermission()"))
    @GetMapping("/{loopId}")
    public ResponseResult getLoop(@PathVariable("loopId") String loopId){
        return iLoopService.getLoop(loopId);
    }

}
